package com.jsmtr.rms.controller.DUserResume;

import com.jsmtr.rms.entity.ProjectInfo;
import com.jsmtr.rms.entity.ProjectInfoFlow;
import com.jsmtr.rms.entity.ProjectInfoJobs;
import com.jsmtr.rms.service.IUtilService;
import com.jsmtr.rms.utils.ResultBean;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * @author: cyx
 * @description:
 * @date: Created in 2019/3/21 16:01
 * @modified by:
 */
@Controller
public class DUserResumeFlowStateController {

    @Resource
    private IUtilService utilService;

    @ResponseBody
    @RequestMapping(value = "/DUserResume/getFlowStateJson")
    public ResultBean getFlowStateJson(HttpServletRequest request, HttpServletResponse response){
        StringBuffer result=new StringBuffer();
         String fid=request.getParameter("fid");
        ResultBean resultBean =new ResultBean();
       try {
           ProjectInfoFlow infoFlow=utilService.getFlow(fid);
           List statesList=new ArrayList();
           statesList.add("全部");
           if(infoFlow!=null){
               String flowName=infoFlow.getFname()==null?infoFlow.getNickname():infoFlow.getFname();
                List states;
               if (infoFlow.getPid().toLowerCase().indexOf("c_")>=0){
                   states = utilService.groupZZStateByFid(fid,flowName);
               }else{
                   states = utilService.groupNomalStateByFid(fid,flowName);
               }
               if (flowName.equalsIgnoreCase("面试")){
                   if (states!=null&&states.size()>0){
                       statesList.addAll(states);
                   }else{
                       statesList.add("未面试");
                   }
               }else if (flowName.equalsIgnoreCase("笔试")){
                   if (states!=null&&states.size()>0){
                       statesList.addAll(states);
                   }else{
                       statesList.add("未笔试");
                   }
               }else if (flowName.equalsIgnoreCase("实作")){
                   if (states!=null&&states.size()>0){
                       statesList.addAll(states);
                   }else{
                       statesList.add("未实作");
                   }
               }else{
                   if (states!=null&&states.size()>0){
                       statesList.addAll(states);
                   }else{
                       statesList.add("未处理");
                   }
               }
               resultBean.setState(true);
               resultBean.setMessage("操作成功!");
               resultBean.setDatas(statesList);
           }

       }catch (Exception e){
            resultBean.setMessage("读取流程状态失败");
       }

        return resultBean;
    }
}
